@extends('layouts.app')
@section('title','帖子新增页')
@section('styles')
     <link rel="stylesheet" type="text/css" href="{{ asset('css/simditor.css') }}">
@stop

@section('content')
    <div class="row">
        <div class="offset-md-2 col-md-8">
            <div class="card">
                <div class="card-header">
                    <h4><i class="fa fa-add  pt-3"></i> 帖子的新增</h4>
                </div>
                <div class="card-body">
                    <form action="{{route('topic.store')}}"
                          method="POST" accept-charset="UTF-8">
                        @csrf
                        @include('shared._error')
                        <div class="mt-3">
                            <label for="title">帖子标题:</label>
                            <input type="text" class="form-control" id="title" name="title" value="{{old('title')}}"/>
                        </div>
                        <div class="mt-3">
                            <label for="category_id">所属分类:</label>
                            <select id="category_id" class="form-select" name="category_id" required>
                                <option value="" selected hidden disabled>请选择分类...</option>
                                @foreach($categories as $category)
                                    <option value="{{$category->id}}">{{$category->name}}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="mt-3">
                            <label for="editor">帖子内容:</label>
                            <textarea rows="6" name="body" id="editor" class="form-control">{{old('introduction')}}</textarea>
                        </div>
                        <div class="mt-3 text-center">
                            <button class="btn btn-primary" type="submit">提交</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@stop

@section('scripts')
    <script type="text/javascript" src="{{ asset('js/module.js') }}"></script>
    <script type="text/javascript" src="{{ asset('js/hotkeys.js') }}"></script>
    <script type="text/javascript" src="{{ asset('js/uploader.js') }}"></script>
    <script type="text/javascript" src="{{ asset('js/simditor.js') }}"></script>

    <script>
        $(document).ready(function(){
            let editor = new Simditor({
                textarea:$('#editor'),
                upload:{
                    url:"{{route('topic.upload_image')}}",
                    params: {
                        _token:"{{  csrf_token() }}"
                    },
                    fileKey: 'upload_file',
                    connectionCount: 3,
                    leaveConfirm: '文件上传中，关闭页面将取消上传，您确定要取消吗?'
                },
                pasteImage: true,
            })
        });
    </script>
@stop

